package com.yanqu.road.server.gameplayer.module.topiclink;

import com.yanqu.road.entity.activity.topiclink.TopicLinkConfig;
import com.yanqu.road.pb.topicLink.TopicLinkProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.manger.config.TopicLinkMgr;
import com.yanqu.road.server.protocol.ClientProtocol;

import java.util.List;

/**
 * 同步圈子链接模块
 */

public class TopicLinkModule extends GeneralModule {


    public TopicLinkModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean saveData() {
        return true;
    }

    @Override
    public void afterLogin() {
        syncTopicLinkConfig();
    }

    public void syncTopicLinkConfig(){
        List<TopicLinkConfig> topicLinkConfigList = TopicLinkMgr.getTopicLinkConfigList(player.getAppId());
        if (topicLinkConfigList!=null && !topicLinkConfigList.isEmpty()){
            TopicLinkProto.TopicLinkConfigSyncMsg.Builder builder = TopicLinkProto.TopicLinkConfigSyncMsg.newBuilder();
            for (TopicLinkConfig topicLinkConfig: topicLinkConfigList){
                TopicLinkProto.TopicLinkConfigMsg.Builder topicLinkConfigBuilder = TopicLinkProto.TopicLinkConfigMsg.newBuilder();
                topicLinkConfigBuilder.setActivityType(topicLinkConfig.getActivityType());
                topicLinkConfigBuilder.setActivityChildType(topicLinkConfig.getActivityChildType());
                topicLinkConfigBuilder.setAndroidLink(topicLinkConfig.getAndroidLink());
                topicLinkConfigBuilder.setIosLink(topicLinkConfig.getIosLink());
                topicLinkConfigBuilder.setH5Link(topicLinkConfig.getH5Link());
                builder.addTopicLinkConfigMsg(topicLinkConfigBuilder);
            }
            player.sendPacket(ClientProtocol.U_SYNC_TOPIC_LINK, builder);
        }
    }
}
